//
//  SuggestViewController.m
//  MM
//
//  Created by 郑渊文 on 5/20/15.
//  Copyright (c) 2015 王晨辉. All rights reserved.
//

#import "SuggestViewController.h"
#import "CommonMacro.h"

@interface SuggestViewController ()<UITextFieldDelegate,UITextViewDelegate>
{
    UITextField *phoneNum;
    UITextView *suggestion;
     UIButton *backBtn;
    UIView *myBgView;
}
@end

@implementation SuggestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initSubViews];
    self.title = @"意见反馈";
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initSubViews
{
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.view addGestureRecognizer:tap];

    
    if (IS_IPHONE_4_OR_LESS) {
        UIScrollView *bgView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        bgView.contentSize = CGSizeMake(SCREEN_WIDTH, 568);
        bgView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:bgView];
        myBgView = bgView;
    }
    else
    {
        
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        bgView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:bgView];
        myBgView = bgView;
    }

    
    self.navigationItem.title = @"消息中心";
    [self.navigationController.navigationBar setTranslucent:NO];//设置navigationbar的半透明
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#34bd81" alpha:1]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

    self.view.backgroundColor = [UIColor clearColor];
    
    
    //自定义左右按钮
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
     
                      forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(back)
     
     forControlEvents:UIControlEventTouchUpInside];
    
    button.frame = CGRectMake(0, 0, 20, 15);
    
    
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    
    phoneNum = [[UITextField alloc]initWithFrame:CGRectMake(30, 20 , SCREEN_WIDTH-60, 50)];
    phoneNum.delegate = self;
    phoneNum.placeholder = @"客户手机号码";
    phoneNum.backgroundColor = [UIColor whiteColor];
    phoneNum.layer.borderColor = UIColorWithRGBA(232, 234, 237, 1).CGColor;
    phoneNum.layer.borderWidth = 1;
    phoneNum.layer.cornerRadius =5;
    [myBgView addSubview:phoneNum];
    
    suggestion = [[UITextView alloc]initWithFrame:CGRectMake(30, 100, SCREEN_WIDTH-60, 200)];
    suggestion.delegate = self;
     suggestion.layer.borderColor = UIColorWithRGBA(232, 234, 237, 1).CGColor;
    suggestion.text = @"感谢你对麦苗公学的关注，你得意见我们一定认真听取";
    suggestion.textColor = [UIColor lightGrayColor];
    suggestion.backgroundColor = [UIColor whiteColor];
    suggestion.layer.cornerRadius =5;
    suggestion.layer.masksToBounds = YES;
    suggestion.layer.borderWidth = 1;
    [myBgView addSubview:suggestion];
    
    
    UIButton *upLoad = [[UIButton alloc]initWithFrame:CGRectMake(30, 320, SCREEN_WIDTH-60, 40)];
    [upLoad addTarget:self action:@selector(addSugestion) forControlEvents:UIControlEventTouchUpInside];
    [upLoad setImage :[UIImage imageNamed:@"提交"] forState:UIControlStateNormal];
    [myBgView addSubview:upLoad];

    
}


-(BOOL)textViewShouldBeginEditing:(UITextView *)textView

{
    
    textView.text=@"";
    
    suggestion.textColor = [UIColor blackColor];
    
    return YES;
    
}
- (void)tap:(UITapGestureRecognizer *)recognizer
{
    [phoneNum resignFirstResponder];
    [suggestion resignFirstResponder];
}

-(void)addSugestion
{
    NSDictionary *param4 = @{@"userId":@"1",@"phoneNum":phoneNum.text,@"suggestion":suggestion.text};
    
    [UserDAL getAppsuggestionParams:param4 withBlock:^(NSDictionary *data, NSError *error) {
        if (data) {
            ////NSLog(@"=========================%@",data);
            
            [self ShowProgressHUDwithMessage:data[@"msg"]];
            
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
            

        }else
        {
            alert(@"提交失败");
        }
    }];

}

-(void)back
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark - HUD
- (void)ShowProgressHUDwithMessage:(NSString *)msg
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = msg;
    hud.dimBackground = NO;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
